home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / database / bltw110.zip / BW_LAI11.C < prev    next >
C/C++ Source or Header  |  1994-08-18  |  10KB  |  330 lines

  1.  
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <time.h>
  8.  
  9. #include "BULLET.h"
  10.  
  11. #pragma pack(1)        /* C7 packs to EVEN by default
  12.             Must pack any Bullet-used data 
  13.             structures to standard byte-
  14.             alignment with any compiler! 
  15.             YOUR PROGRAM WILL NOT RUN CORRECTLY
  16.             UNLESS THIS IS SO!
  17.             */
  18.                
  19. /* 
  20.    12-Jul-94
  21.    BW_LAI11.C -chh
  22.    
  23.    The RC resource compiler may generate a warning about the use of
  24.    hard-code data segment loads with the DGROUP value.  The warning is
  25.    relevant to a multi-instanced program, which Bullet code won't be
  26.    (can't be). Future versions will remove this limitation (i.e., a 
  27.    DLL version will be available).
  28.    
  29.    18-Mar-94
  30.    BW_LAI11.C -chh
  31.    
  32.    Minor modifications from the previous BC_LAI10.C (a little understanding
  33.    helps) but essentially done for the Bullet Windows (QuickWin of C7)
  34.    test program. Running from Windows Standard Mode fails because Windows
  35.    does not properly handle INT21/65xx calls. In order to run from Standard
  36.    Mode you must either supply your own collate table (demonstrated below), 
  37.    or use a straight ASCII sort. Windows does handle INT21/65xx from Enhanced
  38.    Mode correctly.
  39. */
  40.    
  41. /* Country code 001 collate table from US MS-DOS 6.20 */
  42.  
  43. unsigned char cc001[256] =
  44. {
  45. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
  46. 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
  47. 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
  48. 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
  49. 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
  50. 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
  51. 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
  52. 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x7B,0x7C,0x7D,0x7E,0x7F,
  53. 0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41,
  54. 0x45,0x41,0x41,0x4F,0x4F,0x4F,0x55,0x55,0x59,0x4F,0x55,0x24,0x24,0x24,0x24,0x24,
  55. 0x41,0x49,0x4F,0x55,0x4E,0x4E,0xA6,0xA7,0x3F,0xA9,0xAA,0xAB,0xAC,0x21,0x22,0x22,
  56. 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
  57. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,
  58. 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,
  59. 0xE0,0x53,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
  60. 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF
  61. };
  62.  
  63.             
  64. /* --test raw speed using 32-bit long integer key, unique
  65.    1) this test uses a non-standard binary field as a sort field
  66.    2) this code is for raw speed tests--it's straight inline
  67.    
  68.    Note: memory model must be medium, large, or huge */
  69.  
  70. struct memorypack MP;
  71. struct initpack IP;
  72. struct exitpack EP;
  73. struct fielddesctype fieldlist[2];
  74. struct createdatapack CDP;
  75. struct createkeypack CKP;
  76. struct dosfilepack DFP;
  77. struct openpack OP;
  78. struct accesspack AP;
  79. struct exitpack EP;
  80.  
  81. int    rez, level, ccflag;
  82. div_t    div_rez;
  83. time_t    starttime, endtime;
  84.  
  85. char    tmpstr[129];
  86.  
  87. char     NameDAT[] = ".\\BINTEST.DBB";
  88. char     NameIX1[] = ".\\BINTEST.IX1";
  89.  
  90. char    kx1[] = "CODENUMBER";
  91.  
  92. unsigned handdat, handix1;
  93.  
  94. struct testrectype {
  95.     char  tag;
  96.     long  codenumber;
  97.     char  codename[11];
  98. }; /* test program record length=16 bytes */
  99. struct testrectype testrec;
  100.  
  101. char    keybuffer[64];        /* MUST supply a work buffer for keys */
  102.                             /* a single one can be shared unless you */
  103.                             /* want to preserve the key buffer for each */
  104.                             /* access pack */
  105.                             
  106. long    recs2add;
  107. long    low;
  108. long    high;
  109. long    i;
  110.           
  111. #pragma pack()
  112.  
  113.  
  114. int main()
  115. {
  116.  
  117.    strcpy(fieldlist[0].fieldname, "CODENUMBER");
  118.    strcpy(fieldlist[0].fieldtype, "B");
  119.    fieldlist[0].fieldlen = 4;
  120.    fieldlist[0].fielddc = 0;
  121.    strcpy(fieldlist[1].fieldname, "CODENAME");
  122.    strcpy(fieldlist[1].fieldtype, "C");
  123.    fieldlist[1].fieldlen = 11;
  124.    fieldlist[1].fielddc = 0;
  125.  
  126.    /* excuses, excuses */
  127.  
  128.    printf("BC_LAI11.C - LONG INT, SIGNED, UNIQUE long int, add/reindex speed test\n");
  129.    printf("--uses non-standard data files with binary field values, not DBF\n");
  130.    printf(">> USING DIRECTORY : .\\ \n\n");
  131.  
  132.    level = 100;
  133.    MP.func = MEMORYXB;
  134.    rez = BULLET(&MP);
  135.    printf("memory avail   : %lu\n",MP.memory);
  136.  
  137.    if (MP.memory < 40000L) {
  138.       rez = 8;
  139.       goto Abend;
  140.    }
  141.               
  142.    ccflag = 0;
  143.    printf("Override machine default collate and use embedded table? (Y/N)");
  144.    gets(tmpstr);
  145.    if (toupper(*tmpstr) == 'Y') 
  146.    {
  147.       ccflag = 1;
  148.       printf("Using embedded collate table (country code=001)\n");
  149.    }
  150.    else
  151.     printf("Using machine default collate table\n");
  152.   
  153.    
  154.    level = 110;
  155.    IP.func = INITXB;
  156.    IP.jftmode = 0;
  157.    rez = BULLET(&IP);
  158.    if (rez != 0) goto Abend;
  159.  
  160. #if 0
  161.    level = 120;
  162.    EP.func = ATEXITXB;
  163.    rez = BULLET(&EP);
  164.    if (rez != 0) goto Abend;
  165. #endif
  166.  
  167.    level = 130;                /* disregard not found errors */
  168.    DFP.func = DELETEFILEDOS;
  169.    DFP.filenameptr = NameDAT;
  170.    rez = BULLET(&DFP);
  171.    DFP.filenameptr = NameIX1;
  172.    rez = BULLET(&DFP);
  173.  
  174.    level = 1000;
  175.    CDP.func = CREATEDXB;
  176.    CDP.filenameptr = NameDAT;
  177.    CDP.nofields = 2;
  178.    CDP.fieldlistptr = fieldlist;
  179.    CDP.fileid = 255;
  180.    rez = BULLET(&CDP);
  181.    if (rez !=0) goto Abend;
  182.  
  183.    level = 1010;
  184.    OP.func = OPENDXB;
  185.    OP.filenameptr = NameDAT;
  186.    OP.asmode = READWRITE | DENYNONE;
  187.    rez = BULLET(&OP);
  188.    if (rez !=0) goto Abend;
  189.    handdat = OP.handle;
  190.  
  191.    level = 1100;
  192.    CKP.func = CREATEKXB;
  193.    CKP.filenameptr = NameIX1;
  194.    CKP.keyexpptr = kx1;
  195.    CKP.xblink = handdat;
  196.    CKP.keyflags = cLONG | cSIGNED | cUNIQUE;
  197.    if (ccflag) 
  198.    {
  199.       CKP.codepageid = 437;    /* identify collate sequence -- must be */
  200.       CKP.countrycode = 1;    /* non-zero else collateptr ignored */
  201.       CKP.collateptr = cc001; /* these values are specifically for */
  202.                               /* the table cc001, coded above */
  203.    }
  204.    else
  205.    { 
  206.       CKP.codepageid = -1;  /* use this unless you specifically */
  207.       CKP.countrycode = -1; /* need to use your own collate table */
  208.       CKP.collateptr = NULL; /* as shown directly above */
  209.    }
  210.    rez = BULLET(&CKP);
  211.    if (rez !=0) goto Abend;
  212.  
  213.    level = 1110;
  214.    OP.func = OPENKXB;
  215.    OP.filenameptr = NameIX1;
  216.    OP.asmode = READWRITE | DENYNONE;
  217.    OP.xblink = handdat;
  218.    rez = BULLET(&OP);
  219.    if (rez !=0) goto Abend;
  220.    handix1 = OP.handle;
  221.  
  222.    AP.func = ADDRECORDXB;
  223.    AP.handle = handdat;
  224.    AP.recptr = &testrec;
  225.    AP.keyptr = keybuffer;
  226.    AP.nextptr = NULL;
  227.  
  228.    testrec.tag = ' ';
  229.    strcpy(testrec.codename, "xxxSAMExxx");
  230.  
  231.    printf("Recs to add/reindex: ");
  232.    gets(tmpstr);
  233.    recs2add = atol(tmpstr);
  234.    if (recs2add == 0L) recs2add = 5L;
  235.  
  236.    level = 1200;
  237.    low = -3L;
  238.    high = low + recs2add - 1L;
  239.    printf("Adding %ld records ( keys %ld to %ld )... ",recs2add,low,high);
  240.  
  241.    time(&starttime);
  242.    for (i = low; i < (recs2add+low); i++) {
  243.       testrec.codenumber = i;
  244.       rez = BULLET(&AP);
  245.       if (rez !=0) goto Abend;
  246.    }
  247.    time(&endtime);
  248.    printf("%lu secs.\n",(endtime - starttime));
  249.  
  250.    level = 1210;
  251.    printf("Reindexing... ");
  252.    AP.func = REINDEXXB;
  253.    AP.handle = handix1;
  254.    time(&starttime);
  255.    rez = BULLET(&AP);
  256.    time(&endtime);
  257.    if (rez != 0) {
  258.       rez = AP.stat;    /* MUST take AP.stat since a xaction routine */
  259.       goto Abend;       /* see docs and !README2.TXT for more */
  260.    }
  261.    printf("%lu secs\n\n",(endtime - starttime));
  262.  
  263.    level = 1300;
  264.    AP.func = GETFIRSTXB;
  265.    rez = BULLET(&AP);
  266.    printf("  The first 5 key/recs\n");
  267.    printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  268.    for (i=1;i < 5; i++) {
  269.       if (rez != 0) break;
  270.       AP.func = GETNEXTXB;
  271.       rez = BULLET(&AP);
  272.       printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  273.    }
  274.    if (rez == 202) rez = 0;
  275.    if (rez != 0) goto Abend;
  276.    puts(" ");
  277.  
  278.    level = 1310;
  279.    AP.func = GETLASTXB;
  280.    rez = BULLET(&AP);
  281.    printf("  The last 5 key/recs\n");
  282.    printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  283.    for (i=1;i < 5; i++) {
  284.       if (rez != 0) break;
  285.       AP.func = GETPREVXB;
  286.       rez = BULLET(&AP);
  287.       printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  288.    }
  289.    if (rez == 203) rez = 0;
  290.    if (rez != 0) goto Abend;
  291.    
  292.    level = 1311;
  293.    printf("  Finding the last gotten key, (in AP.keybuffer already)\n");
  294.    AP.func = GETEQUALXB;
  295.    rez = BULLET(&AP);
  296.    printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  297.    if (rez != 0) goto Abend;
  298.    
  299.    level = 1312;
  300.    printf("  Finding key of 5\n");
  301.    AP.func = GETEQUALXB;
  302.    *((long *)keybuffer) = 5L;
  303.    rez = BULLET(&AP);
  304.    printf("%7lu %7ld %.10s\n",AP.recno,testrec.codenumber,testrec.codename);
  305.    if (rez != 0) goto Abend;
  306.    
  307.    puts("Okay.");
  308.    EP.func = EXITXB;
  309.    rez = BULLET(&EP);
  310.    return(0);
  311.    /* program exit */
  312.  
  313.  
  314.    /*----------------------------------------------*/
  315.    /* that's right, we go to a termination routine */
  316.  
  317. Abend:
  318.    printf("Error: %u at level %u while performing ",rez,level);
  319.    switch (level) {
  320.    case 100:
  321.       printf("a memory request of 140K.\n");
  322.       break;
  323.    default:
  324.       printf("(See source)\n");    /* just check the source */
  325.    }
  326.  
  327.    exit(1);
  328. }
  329.  
  330.